home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / sample (traffic light) / sample.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  9.4 KB  |  219 lines

  1. /*
  2.     File:        Sample.h
  3.  
  4.     Contains:    MultiFinder-Aware Simple Sample Application
  5.  
  6.     Written by: Sample is an example application that demonstrates how to
  7.                 initialize the commonly used toolbox managers, operate 
  8.                 successfully under MultiFinder, handle desk accessories, 
  9.                 and create, grow, and zoom windows.
  10.     
  11.                 It does not by any means demonstrate all the techniques 
  12.                 you need for a large application. In particular, Sample 
  13.                 does not cover exception handling, multiple windows/documents, 
  14.                 sophisticated memory management, printing, or undo. All of 
  15.                 these are vital parts of a normal full-sized application.
  16.     
  17.                 This application is an example of the form of a Macintosh 
  18.                 application; it is NOT a template. It is NOT intended to be 
  19.                 used as a foundation for the next world-class, best-selling, 
  20.                 600K application. A stick figure drawing of the human body may 
  21.                 be a good example of the form for a painting, but that does not 
  22.                 mean it should be used as the basis for the next Mona Lisa.
  23.     
  24.                 We recommend that you review this program or TESample before 
  25.                 beginning a new application.    
  26.  
  27.     Copyright:    Copyright © 1989-1999 by Apple Computer, Inc., All Rights Reserved.
  28.  
  29.                 You may incorporate this Apple sample source code into your program(s) without
  30.                 restriction. This Apple sample source code has been provided "AS IS" and the
  31.                 responsibility for its operation is yours. You are not permitted to redistribute
  32.                 this Apple sample source code as "Apple sample source code" after having made
  33.                 changes. If you're going to re-distribute the source, we require that you make
  34.                 it clear in the source that the code was descended from Apple sample source
  35.                 code, but that you've made changes.
  36.  
  37.     Change History (most recent first):
  38.                 8/13/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  39.                 
  40.  
  41. */
  42.  
  43. /* In MPW 3.0 and THINK C we can use actual prototypes for parameter type checking. */
  44. /* Function prototypes for all functions in this program. */
  45.  
  46. #ifndef rez
  47. void EventLoop( void );
  48. void DoEvent( EventRecord *event );
  49. void AdjustCursor( Point mouse, RgnHandle region );
  50. void GetGlobalMouse( Point *mouse );
  51. void DoUpdate( WindowPtr window );
  52. void DoActivate( WindowPtr window, Boolean becomingActive );
  53. void DoContentClick( WindowPtr window );
  54. void DrawWindow( WindowPtr window );
  55. void AdjustMenus( void );
  56. void DoMenuCommand( long menuResult );
  57. void SetLight( WindowPtr window, Boolean newStopped );
  58. Boolean DoCloseWindow( WindowPtr window );
  59. void Terminate( void );
  60. void ForceEnvirons( void );
  61. Boolean IsAppWindow( WindowPtr window );
  62. Boolean IsDAWindow( WindowPtr window );
  63. void AlertUser( void );
  64. void Initialize( void );
  65. Boolean GoGetRect( short rectID, Rect *theRect );
  66. Boolean TrapAvailable( short tNumber, TrapType tType );
  67. #endif
  68.  
  69. /*    These #defines correspond to values defined in the Pascal source code.
  70.     Sample.c and Sample.r include this file. */
  71.  
  72. /*    Determining an application's minimum size to request from MultiFinder depends
  73.     on many things, each of which can be unique to an application's function,
  74.     the anticipated environment, the developer's attitude of what constitutes
  75.     reasonable functionality and performance, etc. Here is a list of some things to
  76.     consider when determining the minimum size (and preferred size) for your
  77.     application. The list is pretty much in order of importance, but by no means
  78.     complete.
  79.     
  80.     1.    What is the minimum size needed to give almost 100 percent assurance
  81.         that the application won't crash because it ran out of memory? This
  82.         includes not only things that you do have direct control over such as
  83.         checking for NIL handles and pointers, but also things that some
  84.         feel are not so much under their control such as QuickDraw and the
  85.         Segment Loader.
  86.         
  87.     2.    What kind of performance can a user expect from the application when
  88.         it is running in the minimum memory configuration? Performance includes
  89.         not only speed in handling data, but also things like how many documents
  90.         can be opened, etc.
  91.         
  92.     3.    What are the typical sizes of scraps [is a boy dog] that a user might
  93.         wish to work with when lauching or switching to your application? If
  94.         the amount of memory is too small, the scrap may get lost [will have
  95.         to be shot]. This can be quite frustrating to the user.
  96.         
  97.     4.    The previous items have concentrated on topics that tend to cause an
  98.         increase in the minimum size to request from MultiFinder. On the flip
  99.         side, however, should be the consideration of what environments the
  100.         application may be running in. There may be a high probability that
  101.         many users with relatively small memory configurations will want to
  102.         avail themselves of your application. Or, many users might want to use it
  103.         while several other, possibly related/complementary applications are
  104.         running. If that is the case, it would be helpful to have a fairly
  105.         small minimum size.
  106.     
  107.     So, what did we decide on Sample? First, Sample has little risk of
  108.     running out of memory once it starts. Second, performance isn't much
  109.     of an issue since it doesn't do much and multiple windows are not
  110.     allowed. Third, there are no edit operations in Sample itself, so we
  111.     just want to provide enough space for a reasonable scrap to survive
  112.     between desk accessory launches. Lastly, Sample should intrude as little
  113.     as possible, so the effort should be towards making it as small as possible.
  114.     We looked at some heap dumps while the application was running under
  115.     various partition sizes. With a size of 23K, there was approximately
  116.     8-9K free, which is a good 'slop' factor in an application like this
  117.     which doesn't do much, but where we'd still like the scrap to survive
  118.     most of the time. */
  119.  
  120. #define kMinSize    23                /* application's minimum size (in K) */
  121.  
  122. /*    We made the preferred size bigger than the minimum size by 12K, so that
  123.     there would be even more room for the scrap, FKEYs, etc. */
  124.  
  125. #define kPrefSize    35                /* application's preferred size (in K) */
  126.  
  127. #define    rMenuBar    128                /* application's menu bar */
  128. #define    rAboutAlert    128                /* about alert */
  129. #define    rUserAlert    129                /* error user alert */
  130. #define    rWindow        128                /* application's window */
  131. #define rStopRect    128                /* rectangle for Stop light */
  132. #define rGoRect        129                /* rectangle for Go light */
  133.  
  134. /* kSysEnvironsVersion is passed to SysEnvirons to tell it which version of the
  135.    SysEnvRec we understand. */
  136.  
  137. #define    kSysEnvironsVersion        1
  138.  
  139. /* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
  140.    by MultiFinder. Once we determine that an event is an osEvent, we look at the
  141.    high byte of the message sent to determine which kind it is. To differentiate
  142.    suspend and resume events we check the resumeMask bit. */
  143.  
  144. #define    kOSEvent                app4Evt    /* event used by MultiFinder */
  145. #define    kSuspendResumeMessage    1        /* high byte of suspend/resume event message */
  146. #define    kResumeMask                1        /* bit of message field for resume vs. suspend */
  147. #define    kMouseMovedMessage        0xFA    /* high byte of mouse-moved event message */
  148. #define    kNoEvents                0        /* no events mask */
  149.  
  150. /* The following constants are used to identify menus and their items. The menu IDs
  151.    have an "m" prefix and the item numbers within each menu have an "i" prefix. */
  152.  
  153. #define    mApple                    128        /* Apple menu */
  154. #define    iAbout                    1
  155.  
  156. #define    mFile                    129        /* File menu */
  157. #define    iNew                    1
  158. #define    iClose                    4
  159. #define    iQuit                    12
  160.  
  161. #define    mEdit                    130        /* Edit menu */
  162. #define    iUndo                    1
  163. #define    iCut                    3
  164. #define    iCopy                    4
  165. #define    iPaste                    5
  166. #define    iClear                    6
  167.  
  168. #define    mLight                    131        /* Light menu */
  169. #define    iStop                    1
  170. #define    iGo                        2
  171.  
  172. /*    1.01 - kTopLeft - This is for positioning the Disk Initialization dialogs. */
  173.  
  174. #define kDITop                    0x0050
  175. #define kDILeft                    0x0070
  176.  
  177. /*    1.01 - kMinHeap - This is the minimum result from the following
  178.     equation:
  179.         
  180.         ORD(GetApplLimit) - ORD(ApplicZone)
  181.         
  182.     for the application to run. It will insure that enough memory will
  183.     be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  184.     application, and still give the application some 'breathing room'.
  185.     To derive this number, we ran under a MultiFinder partition that was
  186.     our requested minimum size, as given in the 'SIZE' resource. */
  187.      
  188. #define kMinHeap                21 * 1024
  189.     
  190. /*    1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
  191.     at initialization time, for the application to run. This number acts
  192.     as a double-check to insure that there really is enough memory for the
  193.     application to run, including what has been taken up already by
  194.     pre-loaded resources, the scrap, code, and other sundry memory blocks. */
  195.      
  196. #define kMinSpace                8 * 1024
  197.  
  198. /* kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
  199.  
  200. #define kExtremeNeg                -32768
  201. #define kExtremePos                32767 - 1 /* required to address an old region bug */
  202.  
  203. /* these #defines are used to set enable/disable flags of a menu */
  204.  
  205. #define AllItems    0b1111111111111111111111111111111    /* 31 flags */
  206. #define NoItems        0b0000000000000000000000000000000
  207. #define MenuItem1    0b0000000000000000000000000000001
  208. #define MenuItem2    0b0000000000000000000000000000010
  209. #define MenuItem3    0b0000000000000000000000000000100
  210. #define MenuItem4    0b0000000000000000000000000001000
  211. #define MenuItem5    0b0000000000000000000000000010000
  212. #define MenuItem6    0b0000000000000000000000000100000
  213. #define MenuItem7    0b0000000000000000000000001000000
  214. #define MenuItem8    0b0000000000000000000000010000000
  215. #define MenuItem9    0b0000000000000000000000100000000
  216. #define MenuItem10    0b0000000000000000000001000000000
  217. #define MenuItem11    0b0000000000000000000010000000000
  218. #define MenuItem12    0b0000000000000000000100000000000
  219.